package wnxy.wn44.shopwn.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import wnxy.wn44.shopwn.interceptor.FirstIntercepter;
import wnxy.wn44.shopwn.interceptor.SecondInterceptor;

/**
 * @author Administrator
 */
@Configuration
public class SecurityConfig {

    /**
     * 拦截器的加载在组件前，所以在拦截器中注入组件为null
     * @return
     */
    @Bean
    public FirstIntercepter firstInterceptor(){
        return new FirstIntercepter();
    }
    @Bean
    public SecondInterceptor secondInterceptor(){
        return new SecondInterceptor();
    }
    @Bean
    public WebMvcConfigurer webMvcConfigurer(){
        return new WebMvcConfigurer() {
            @Override
            public void addInterceptors(InterceptorRegistry registry) {
                registry.addInterceptor(firstInterceptor())
                        .addPathPatterns("/index.html");
                registry.addInterceptor(secondInterceptor())
                        .addPathPatterns("/shop/addShop","/shop/removeById","/shop/updateShop");
            }
        };
    }
}
